home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_214 / mandelvroom / src / orbit.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  7KB  |  272 lines

  1. /*
  2.  * MandelVroom 2.0
  3.  *
  4.  * (c) Copyright 1987,1989  Kevin L. Clague, San Jose, CA
  5.  *
  6.  * All rights reserved.
  7.  *
  8.  * Permission is hereby granted to distribute this program's source
  9.  * executable, and documentation for non-comercial purposes, so long as the
  10.  * copyright notices are not removed from the sources, executable or
  11.  * documentation.  This program may not be distributed for a profit without
  12.  * the express written consent of the author Kevin L. Clague.
  13.  *
  14.  * This program is not in the public domain.
  15.  *
  16.  * Fred Fish is expressly granted permission to distribute this program's
  17.  * source and executable as part of the "Fred Fish freely redistributable
  18.  * Amiga software library."
  19.  *
  20.  * Permission is expressly granted for this program and it's source to be
  21.  * distributed as part of the Amicus Amiga software disks, and the
  22.  * First Amiga User Group's Hot Mix disks.
  23.  *
  24.  * contents: this file contains the functions that open, maintain and
  25.  * close the orbit window.
  26.  */
  27.  
  28. #define PARSEGOOD 0
  29. #define PARSEBAD  1
  30.  
  31. #include "mandp.h"
  32. #include "parms.h"
  33.  
  34. SHORT MaxOrbit = 32;
  35. UBYTE OrbitMode = 1;
  36.  
  37. UBYTE OrbitOpen;
  38.  
  39. struct NewWindow NewOrbit = {
  40.    100, 12,                  /* start position           */
  41.    130,80,                   /* width, height            */
  42.  
  43.    (UBYTE) 0, (UBYTE) NORMALPEN,
  44.    NULL,                     /* IDCMP flags */
  45.    /* OrbitWind flags */
  46.    WINDOWCLOSE | WINDOWDEPTH | WINDOWSIZING | WINDOWDRAG | ACTIVATE |
  47.    NOCAREREFRESH | SMART_REFRESH,
  48.    (struct Gadget *) NULL,   /* first gadget             */
  49.    (struct Image *) NULL,    /* user checkmark           */
  50.    (UBYTE *) "Orbit",        /* Title                    */
  51.    (struct Screen *) NULL,   /* pointer to screen        */
  52.    (struct BitMap *) NULL,   /* pointer to superbitmap   */
  53.    20,20,-1,-1,              /* sizing                   */
  54.    CUSTOMSCREEN              /* type of screen           */
  55. };
  56.  
  57. struct Window *OrbitWind;
  58.  
  59. ConfOrbMode( subnum )
  60.   int subnum;
  61. {
  62.   OrbitMode = subnum;
  63. }
  64.  
  65. OrbitCmd( msg )
  66.   register struct IntuiMessage *msg;
  67. {
  68.   static struct Picture *OrbitPict;
  69.   register struct Window *Window;
  70.  
  71.   switch( msg->Class ) {
  72.     case MENUPICK:
  73.     case GADGETDOWN:
  74.          OpenOrbitWind();
  75.          break;
  76.  
  77.     case MOUSEBUTTONS:
  78.  
  79.          Window = (struct Window *) msg->IDCMPWindow;
  80.  
  81.          switch (msg->Code) {
  82.            case SELECTDOWN:
  83.  
  84.                 OrbitPict = (struct Picture *) Window->UserData;
  85.  
  86.                 if (OrbitPict != NULL &&
  87.                   !(OrbitPict->Flags & SCROLL_HAPPENED)) {
  88.  
  89.                   ModifyIDCMP( Window,
  90.                                (long) Window->IDCMPFlags | MOUSEMOVE );
  91.                   DrawOrbit(OrbitPict);
  92.                 }
  93.                 break;
  94.  
  95.            case SELECTUP:
  96.  
  97.                 if (OrbitPict != NULL) {
  98.  
  99.                   ModifyIDCMP( Window,
  100.                                (long) Window->IDCMPFlags & ~MOUSEMOVE );
  101.                   OrbitPict = NULL;
  102.                 }
  103.                 break;
  104.          }
  105.          break;
  106.  
  107.     case MOUSEMOVE:
  108.  
  109.          if (OrbitPict != NULL) {
  110.            DrawOrbit( OrbitPict );
  111.          }
  112.          break;
  113.   }
  114. }
  115.  
  116. DrawOrbit( Pict )
  117.   struct Picture *Pict;
  118. {
  119.   switch( OrbitMode ) {
  120.     case 1:   /* ffp       */
  121.          {    /* 32 bit IEEE float variables */
  122.  
  123.            float CReal_float, CImag_float, ZReal_float, ZImag_float;
  124.  
  125.            if (OpenFFPLibs() != 0)
  126.              return;
  127.  
  128.            /* convert 64 bit IEEE variables into 32 bit IEEE variables */
  129.  
  130.            CReal_float =
  131.              Pict->RealLow + (MouseX-Pict->LeftMarg) * Pict->RealGap;
  132.            CImag_float =
  133.              Pict->ImagLow + (MouseY-Pict->TopMarg) * Pict->ImagGap;
  134.  
  135.            ZReal_float   = Pict->Real;
  136.            ZImag_float   = Pict->Imag;
  137.  
  138.            /*
  139.             * calculate pointers and convert them to pointers to ULONG
  140.             * so that when we indirect off of these and pass the results
  141.             * as parameters they are not promoted to doubles.
  142.             */
  143.  
  144.            DrawOrbitFFP( Pict,
  145.                          *((ULONG *) &CReal_float),
  146.                          *((ULONG *) &CImag_float),
  147.                          *((ULONG *) &ZReal_float),
  148.                          *((ULONG *) &ZImag_float));
  149.          }
  150.          break;
  151.  
  152.     case 0:   /* int 16/32 */
  153.          DrawOrbitInt( Pict );
  154.          break;
  155.  
  156.     case 2:   /* ieee      */
  157.          DrawOrbitIEEE( Pict );
  158.          break;
  159.   }
  160. }
  161.  
  162. struct Gadget *
  163. MakeOrbitGads()
  164. {
  165.   register struct Gadget *Firstgadget;
  166.   register struct IntuiText  *Intui;
  167.  
  168.   struct IntuiText *ShadowIntui();
  169.   struct Border *Border, *MakeShadow();
  170.  
  171.   Firstgadget = MakeBool(-15,TOPMARG, 12,12, 0,ORBTTYPE<<WINDTYPEBITS,NULL);
  172.  
  173.   if (Firstgadget == NULL) {
  174.     return( Firstgadget );
  175.   }
  176.  
  177.   Firstgadget->Flags      |= GRELRIGHT;
  178.   Firstgadget->Activation |= RIGHTBORDER;
  179.  
  180.   Intui = ShadowIntui( "O", 3, 3);
  181.  
  182.   if (Intui == NULL) {
  183.     FreeGadgets( Firstgadget );
  184.     return( NULL );
  185.   }
  186.  
  187.   Firstgadget->GadgetText = Intui;
  188.  
  189. #define NUMPATCHCORNERS 5
  190.  
  191.   Border = MakeShadow( NORMALPEN, NUMPATCHCORNERS );
  192.  
  193.   if ( Border ) {
  194.     InitPatch( Border );
  195.  
  196.     Border->NextBorder = (struct Border *) Firstgadget->GadgetRender;
  197.     Firstgadget->GadgetRender = (APTR) Border;
  198.   }
  199.  
  200.   return( Firstgadget );
  201. }
  202.  
  203. static struct Gadget *OrbitGadgets;
  204. struct Gadget *OrbitResize;
  205.  
  206. /*
  207.  * Open the Orbit window
  208.  */
  209. OpenOrbitWind()
  210. {
  211.   extern struct Window *OpenMyWind();
  212.  
  213.   register struct Window    *Window;
  214.   register struct NewWindow *NewWind;
  215.  
  216.   struct Gadget *gadgets;
  217.  
  218.   if ( OrbitWind == NULL ) {
  219.  
  220.     OrbitGadgets = gadgets = MakeOrbitGads();
  221.  
  222.     if (gadgets == NULL) {
  223.       return( -1 );
  224.     }
  225.  
  226.     Window = OpenMyWind(&NewOrbit, screen, gadgets,
  227.                          NewOrbit.Width, NewOrbit.Height );
  228.  
  229.     if (Window == NULL) {
  230.  
  231.       DispErrMsg("Can't open picture window",0);
  232.       FreeGadgets( OrbitGadgets );
  233.       return( -1 );
  234.  
  235.     } else {
  236.  
  237.       OrbitWind = Window;
  238.       MoveResize( Window, &OrbitResize );
  239.       BorderWindow( Window );
  240.     }
  241.   }
  242.  
  243.   OrbitOpen = 1;
  244.   State = ORBITSTATE;
  245.   SetToPointer();
  246.   return( 0 );
  247. } /* OpenOrbit */
  248.  
  249. /*
  250.  * Close the Orbit Window
  251.  */
  252. CloseOrbitWind()
  253. {
  254.   register struct Window    *Window;
  255.   register struct NewWindow *NewWindow;
  256.  
  257.   Window = OrbitWind;
  258.  
  259.   if ( Window != NULL) {
  260.  
  261.     NewOrbit.LeftEdge = Window->LeftEdge;
  262.     NewOrbit.TopEdge  = Window->TopEdge;
  263.     NewOrbit.Width    = Window->Width;
  264.     NewOrbit.Height   = Window->Height;
  265.  
  266.     CloseMyWind(Window, OrbitGadgets );
  267.  
  268.     OrbitWind    = NULL;
  269.     OrbitGadgets = NULL;
  270.   }
  271. }
  272.